$(document).ready(function(){
    //References
    var sections = $("#accordion");
    var loading = $("#loading");
    var content = $("#content");

    //Manage click events
    sections.click(function(){
        //show the loading bar
        showLoading();
        //load selected section
        switch(this.id){
            case "ua":
                content.slideUp();
                content.load("getUsersActiveTranslations.jsp", hideLoading);
                content.slideDown();
                break;
            case "up":
                content.slideUp();
                content.load("getUsersFinishedTranslations.jsp", hideLoading);
                content.slideDown();
                break;
            case "aa":
                content.slideUp();
                content.load("getAllActiveTranslations.jsp", hideLoading);
                content.slideDown();
                break;
            case "ap":
                content.slideUp();
                content.load("getAllFinishedTranslations.jsp", hideLoading);
                content.slideDown();
                break;
            case "ri":
                content.slideUp();
                content.load("getInvitations.jsp", hideLoading);
                content.slideDown();
                break;
            case "rr":
                content.slideUp();
                content.load("getAllFinishedTranslations.jsp", hideLoading);
                content.slideDown();
                break;
            case "friends":
                content.slideUp();
                content.load("getAllActiveTranslations.jsp", hideLoading);
                content.slideDown();
                break;
            case "scores":
                content.slideUp();
                content.load("getScores.jsp", hideLoading);
                content.slideDown();
                break;
            default:
                //hide loading bar if there is no selected section
                hideLoading();
                break;
        }
    });

    //show loading bar
    function showLoading(){
        loading
        .css({
            visibility:"visible"
        })
        .css({
            opacity:"1"
        })
        .css({
            display:"block"
        })
    ;
    }
    //hide loading bar
    function hideLoading(){
        loading.fadeTo(1000, 0);
    };
});


